import json
import requests


def get_uinfo():
    headers = {
        "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
        "accept-language": "zh-CN,zh;q=0.9",
        "cache-control": "no-cache",
        "pragma": "no-cache",
        "priority": "u=0, i",
        "sec-ch-ua": "\"Chromium\";v=\"130\", \"Google Chrome\";v=\"130\", \"Not?A_Brand\";v=\"99\"",
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": "\"Linux\"",
        "sec-fetch-dest": "document",
        "sec-fetch-mode": "navigate",
        "sec-fetch-site": "same-origin",
        "sec-fetch-user": "?1",
        "upgrade-insecure-requests": "1",
        "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"
    }
    cookies = {
        "SINAGLOBAL": "8051481509490.477.1725417483785",
        "SCF": "AiHhHpjpUWHWnw4SPlbn0Blpe01ucnX2MUzKWh0fqSb96uh2rN6GVyJBgMyb4CP0aWNA7WmWLcNlYlY8hYs04yo.",
        "ULV": "1730362247897:2:1:1:2795453509399.395.1730362247887:1725417483789",
        "ALF": "1733559052",
        "SUB": "_2A25KKAZcDeRhGeNJ6VIS-S7EzDWIHXVpRAeUrDV8PUJbkNAbLRjAkW1NS_5D5YxOEMatinDhQIKyoRGoJG2oLmN3",
        "SUBP": "0033WrSXqPxfM725Ws9jqgMF55529P9D9WhmxpO6_7Bbx4r5qcvFEF1M5JpX5KMhUgL.Fo-Neo501K5RS0.2dJLoI0qLxK-LBo5L12qLxK-LBo2L1h2LxK-LB-BLBK.LxKML1-2L1hBLxK-L1K5L12eLxKqLBK2L12et",
        "XSRF-TOKEN": "dON_EZE-rzC882UKUGWD1HKU",
        "PC_TOKEN": "41d5ffa4ab",
        "WBPSESS": "G9Ff9BQjWfN2Zb8Vj7-gc-yXFs3Y9sWM72U5flc0bOD_g3vusEwwgCVT1Zq8J4AHtyRQtKwyQ8ZeFytfBXqGKm3BVm3PZWC--9PF9kcRdgaCfdfWeuzv1nUrrjhQazTX_vzcTwqrGJgLvPogGQFHeA=="
    }
    url = "https://weibo.com/ajax/profile/info"
    params = {
        "uid": "3919603060" #内蒙古日报
    }
    response = requests.get(url, headers=headers, cookies=cookies, params=params)
    print(response.url,response)
    # print(response.text)
    response.encoding
    return response.json()['data']['user']
def tuisong(text):
    url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=1da5c5d7-e388-476f-9dc5-1658a403d30a"
    # 对 text 进行转义处理，以防破坏 payload 的格式
    escaped_text = json.dumps(text)

    payload = """{
            "msgtype": "text",
            "text": {
                "content": %s
            }
       }"""%escaped_text

    headers = {
      'Content-Type': 'application/json'
    }

    response = requests.request("POST", url, headers=headers, data=payload)

    print(response.text)


if __name__ =="__main__":
    # print(get_uinfo())
    uinfo = get_uinfo()
    user = {}
    user['id'] = uinfo['id']
    user['screen_name'] = uinfo['screen_name']
    user['转评赞'] = uinfo['status_total_counter']['total_cnt']
    user['累计评论'] = uinfo['status_total_counter']['comment_cnt']
    user['累计转发'] = uinfo['status_total_counter']['repost_cnt']
    user['累计获赞'] = uinfo['status_total_counter']['like_cnt']
    user['认证'] = uinfo['verified_reason']
    user['描述'] = uinfo['description']
    user['粉丝量'] = uinfo['followers_count']
    user['关注量'] = uinfo['friends_count']
    data = json.dumps(user,ensure_ascii=False)
    print(data)
    # tuisong(data)
